package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.error.ErrorManager;
import ar.edu.caece.compiler.error.ParsingException;
import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.Recognizer;
import ar.edu.caece.compiler.grammar.TokenRecognizer;
import ar.edu.caece.compiler.grammar.TokenVisitor;
import ar.edu.caece.compiler.grammar.attributes.Attribute;

import ar.edu.caece.compiler.grammar.attributes.StringAttribute;
import ar.edu.caece.compiler.grammar.nonterminals.OP24;
import ar.edu.caece.compiler.grammar.terminals.DivisionNaturalToken;

public class OP24Factory extends AbstractTokenVisitorFactory {

	private static OP24Factory INSTANCE;
	
	public static OP24Factory getInstance() {
		if(INSTANCE==null) INSTANCE = new OP24Factory();
		return INSTANCE;
	}
	
	private OP24Factory() {
		
	}
	
	@Override
	public TokenVisitor makeChainedVisitor(
			final TokenVisitor siguiente) throws Exception {
		return new DivisionNaturalToken.DivisionNaturalChainVisitor(siguiente) {
			
			@Override
			public Recognizer divisionNaturalCase(DivisionNaturalToken llamador) {
				OP24 op24 = new OP24(llamador);
				op24.addAttribute("tipo", new StringAttribute("NATURAL"));
				op24.addAttribute(Attribute.OPERACION, new StringAttribute("DIVISION"));
				return op24;
			}
		};
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		return new DivisionNaturalToken.DivisionNaturalTokenVisitor() {
			
			@Override
			public Recognizer defaultCase(TokenRecognizer llamador) throws Exception {
				ErrorManager.getInstance().manage(llamador,"OP24",new ParsingException("Error de parsing.",OP24.class,llamador));
				return null;
			}
			
			@Override
			public Recognizer divisionNaturalCase(DivisionNaturalToken llamador) {
				OP24 op24 = new OP24(llamador);
				op24.addAttribute("tipo", new StringAttribute("NATURAL"));
				op24.addAttribute(Attribute.OPERACION, new StringAttribute("DIVISION"));

				return op24;
			}
		};
	}
	
	
}
